package com.lt.experiment05.mission02;

import java.util.ArrayList;
import java.util.List;

/**
 * @author LT
 * @version 1.0
 * @PackageName com.lt.experiment05.mission02
 * @ClassName Composite
 * @Description to do
 * @date 2021/11/16 11:58
 */
public class Composite extends Component{
    List<Component> list = new ArrayList<Component>();
    @Override
    public void operation() {
        System.out.print("Composite.");
    }

    @Override
    public void add(Component c) {
        list.add(c);
    }

    @Override
    public void remove(Component c) {
        list.remove(c);
    }

    @Override
    public Component getChild(int i) {
        return list.get(i);
    }

    @Override
    public void print(){
        operation();
        for (Component c: list) {
                c.print();
        }
        System.out.print("}、");
    }
}
